package com.csy.property.controller.community;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.property.community.domain.AjBuilding;
import com.csy.property.community.domain.AjUnit;
import com.csy.property.community.domain.dto.AjBuildingDto;
import com.csy.property.community.domain.vo.AjBuildingVo;
import com.csy.property.community.domain.vo.RoomTree;
import com.csy.property.community.service.AjBuildingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 楼栋
 */
@RestController
@RequestMapping("/system/building")
public class AjBuildingController extends BaseController {

    @Resource
    private AjBuildingService ajBuildingService;

    /**
     * 查询楼栋
     * @param ajBuilding
     * @return
     */
    @GetMapping("/list")
    public PageResult list(AjBuilding ajBuilding){
        startPage();
        List<AjBuilding> ajBuildings = ajBuildingService.selectBuildingList(ajBuilding);
        return getData(ajBuildings);
    }

    /**
     * 楼栋下拉
     * @param ajBuilding
     * @return
     */
    @GetMapping("/queryPullDown")
    public BaseResponse pullDownList(AjBuilding ajBuilding){
        List<AjBuilding> ajBuildings = ajBuildingService.queryPullDown(ajBuilding.getCommunityId());
        return BaseResponse.success(ajBuildings);
    }

    /**
     * 区域楼栋下拉
     * @param ajBuilding
     * @return
     */
    @GetMapping("/queryPullAreaBuilding")
    public BaseResponse queryPullAreaBuilding(AjBuilding ajBuilding){
        List<RoomTree> buildingTrees = ajBuildingService.queryPullAreaBuilding(ajBuilding);
        return BaseResponse.success(buildingTrees);
    }

    /**
     * 根据id查询
     * @param buildingId
     * @return
     */
    @GetMapping("/{buildingId}")
    private BaseResponse getById(@PathVariable("buildingId") Long buildingId){
        AjBuilding building = ajBuildingService.selectById(buildingId);
        return BaseResponse.success(building);
    }

    /**
     * 添加
     * @param ajBuilding
     * @return
     */
    @PostMapping
    private BaseResponse addBuilding(@RequestBody AjBuilding ajBuilding){
        int row = ajBuildingService.insertAjBuilding(ajBuilding);
        if (row > 0){
            return BaseResponse.success(row);
        }
        return BaseResponse.fail("请输入正确的小区等信息！");
    }

    /**
     * 修改
     * @param ajBuilding
     * @return
     */
    @PutMapping
    private BaseResponse updateBuilding(@RequestBody AjBuilding ajBuilding){

        return toAjax(ajBuildingService.updateAjBuilding(ajBuilding));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping("/{buildingId}")
    private BaseResponse delBuilding(@PathVariable("buildingId") Long[] ids){

        return toAjax(ajBuildingService.deleteAjBuilding(ids));
    }
}
